package base.rxjava;

import io.reactivex.*;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;

public class TestMain2 {
    public static void main(String[] args) throws InterruptedException {
        test2();

    }

    static void  test1() throws InterruptedException {
        Observable.create(new ObservableOnSubscribe<Object>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<Object> emitter) throws Exception {
                System.out.println("subscribe------- start--" + Thread.currentThread().getName());
                Thread.sleep(2000);
                emitter.onNext("aaa");
                emitter.onNext("bbb");
                emitter.onComplete();
                System.out.println("subscribe------- end1--" + Thread.currentThread().getName());
            }
        }).subscribeOn(Schedulers.newThread())
          .observeOn(Schedulers.newThread())
          .map(item ->{
            System.out.println("xxxxxxxxxxxxxxxxxxxxxxxx");
            return item;
        });

        System.out.println("33333333");
        Thread.sleep(20000);
    }

    public static void test2() throws InterruptedException {
        Single<String> single = Single.just("zhangshan");
        single.subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.newThread())
                .map(item ->{
                    System.out.println(111111);
                    return item+",--";
                });
        System.out.println(22222);
        System.out.println("####################");
        Thread.sleep(10000);

    }
}
